<template>
  <div class="mian">
  <el-input placeholder="输入文章标题" v-model="title"style="width: 80%;margin-left: 10%"></el-input>
  <EditorTwo ref="editor2" v-on:submit="insertArticle" style="margin-top: 10px;z-index: 10"></EditorTwo>
  </div>
</template>
<script>
  import EditorTwo from "../editor/EditorTwo";
  export default {
    components: {
      EditorTwo,
      // EDITOR: editor
    },
    data () {

      return {
        content:"",
        title:''
      }
    },
  methods: {
    insertArticle(val)
    {
      console.log(this.title);
      console.log(val);
      if(this.title=='' || this.title==null)
      {
        this.$message({
          message:'请填写文章标题',
          type:'warning'
        })
        return
      }
      if(val=='' || val==null)
      {
        this.$message({
          message:'请填写文章内容',
          type:'warning'
        })
        return
      }
      var params={
        title:this.title,
        content:val
      }
      this.$http.post("http://localhost:8989/fornote/article/createNewArticle",params).then(response =>{
        // this.$forceUpdate();
        console.log(response.data);
        if(response.data.code==200)
        {
          this.$message({
            message:response.data.data,
            type:'success'
          })
          this.$router.push("/index")
        }else if(response.data.code!=200)
        {
          this.$message({
            message:"新增文章失败",
            type:"error"
          })
        }

      })
    }
  }
  }
</script>
